#!/bin/bash

#input dao channel shang yi ceng
imagePath=$1
detPath=$2
outPutPath=$3
client_1=root@10.255.130.150
client_2=root@10.255.130.147
all_num=`ls -l "$detPath"|grep "^-"|wc -l`
echo "all_num" $all_num
echo $detPath


#args="/data/ossfs/liu/deep_track/generate_detections_new.py --model /data/program/deep_track_online/networks/mars-small128.ckpt-68577 --image_dir $inputPath/Channel_0$num/Append --detection_dir ${combineKey:replace(${imageDirName},'detOutput')}/Append --output_dir ${combineKey:replace(${imageDirName},${featureDirName})}/Append"


echo $args
echo $all_num
echo $1

function makeArgs()
{
	args="/data/yanguolong/program/deep_track/generate_detections_new.py --model /data/yanguolong/program/deep_track/networks/mars-small128.ckpt-68577 --image_dir $imagePath/Channel_0$1/Append "
	echo $args
	#return $args;
 }

for num in `seq 1 ${all_num}`
do
{
	if [ $num -le 2 ];then
    	echo ${num}
		commend=$(makeArgs "${num}")
		python $commend > gnrtDetLog_Channel0${num} 2>&1
 
	elif [ $num -le 5 ];then
		commend=$(makeArgs "${num}")
		`ssh $client_1 "python $commend > gnrtDetLog_Channel0${num} 2>&1"`
		#echo "ssh $client_1 "python $commend""
		echo ${num}
		echo 'client_1'

	else 
		commend=$(makeArgs "${num}")
		ssh $client_2 "python $commend > gnrtDetLog_Channel0${num} 2>&1"
		echo 'client_2'
		echo 'other'
	fi
} &
done

wait

count=0
cat resultfile | while read line
do
	let count+=1
done
if [ $count -ne 8 ];then
	exit 1
else 
	exit 0
fi

